package Array;

import org.junit.Test;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: Array
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-10-18  13:24
 * @Description: TODO
 * @Version: 1.0
 */
public class 删除有序数组中的重复项II80 {

    // 第一种方法：
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n <= 2) {
            return n;
        }
        int slow = 2, fast = 2;
        while (fast < n) {
            if (nums[slow - 2] != nums[fast]) {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }

    @Test
    public void test(){
        int i = removeDuplicates(new int[]{1, 1, 1, 2, 2, 3});
    }
}
